//
//  ExcelUnitCell.m
//  Common
//
//  Created by shiqing guo on 2018/10/17.
//  Copyright © 2018年 www.bitkinetic.com. All rights reserved.
//

#import "ExcelUnitCell.h"
#import "ExcelTableDefine.h"
#import "Macro.h"
#import "InsetLabel.h"

@interface ExcelUnitCell ()
@property (nonatomic, strong) NSMutableArray<UILabel *> *labelList;
@end

@implementation ExcelUnitCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addSubviews];
        self.labelList = [[NSMutableArray alloc] init];
    }
    return self;
}


- (void)addSubviews
{
    self.contentView.backgroundColor = [UIColor whiteColor];
}


- (void)setDataSource:(NSArray *)dataSource
{
    if (0 == dataSource.count) return;
    
    _dataSource = dataSource;
    for (int i = 0; i < self.contentView.subviews.count; i++) {
        UIView *subView = [self.contentView.subviews objectAtIndex:i];
        [subView removeFromSuperview];
    }
    [self.labelList removeAllObjects];
    
    
    for (int i = 0; i < dataSource.count; i++) {
        InsetLabel *label = [[InsetLabel alloc] initWithFrame:CGRectMake((i * self.ehWidth)  , 0, self.ehWidth, cellHeight - 1)];
        label.backgroundColor = [UIColor whiteColor];
        label.text = [dataSource objectAtIndex:i];
        label.font = SystemFont(14.f);
        label.textAlignment = NSTextAlignmentCenter;
        label.numberOfLines = 0;
        label.textInsets = UIEdgeInsetsMake(0, 10.f, 0, 10.f);
        
        UIView *line = [[UIView alloc] initWithFrame:CGRectMake(i * self.ehWidth, cellHeight - 1.f, self.ehWidth, 1.f)];
        line.backgroundColor = [EPColor epColor_LineBlue];
        
        [self.contentView addSubview:label];
        [self.contentView addSubview:line];
        [self.labelList addObject:label];
    }
}

- (void)setRow:(NSInteger)row
{
    for (int i = 0; i < self.contentView.subviews.count; i++) {
        if ([[self.contentView.subviews objectAtIndex:i] isKindOfClass:[UILabel class]]) {
            UILabel *lbl = [self.contentView.subviews objectAtIndex:i];
            if ((row % 2) == 0) {
                lbl.textColor = [EPColor epColor_Nav];
            } else {
                lbl.textColor = [EPColor epColor_statusMessageGray];
            }
        }
    }
}



@end
